package com.example.algorithm.algorithmService;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.algorithm.department.*;
import com.example.algorithm.enums.CancelTypeEnum;
import com.example.algorithm.mapper.*;
import com.example.algorithm.pojo.*;
import com.example.algorithm.result.ControlPowerDay;
import com.example.algorithm.result.DepartmentControlMark;
import com.example.algorithm.result.PrintResult;
import com.example.algorithm.result.ResultIndexMark;
import com.example.algorithm.utils.AreaJudgeUtils;
import com.example.algorithm.utils.GetDateUtils;
import com.example.algorithm.utils.GetMapKeyUtils;
import com.example.algorithm.utils.SaveMapResultUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Data
@Service
public class ControlAlgorithmService {

    @Resource
    private ResultIndexMarkMapper resultIndexMarkMapper;

    @Resource
    private ControlPowerMapper controlPowerMapper;

    @Resource
    private DataInfoMapper dataInfoMapper;

    @Resource
    private DepartmentMapper departmentMapper;

    @Autowired
    private ControlPowerByMonthService controlPowerByMonthService;

    @Autowired
    private ControlPowerDayService controlPowerDayService;

    @Autowired
    private ControlPowerMonthService controlPowerMonthService;

    @Resource
    private SvYdNumberPartMapper numberPartMapper;

    @Resource
    private SvYdNumberAreaMapper numberAreaMapper;

    @Resource
    private SvYdNumberPlaceMapper numberPlaceMapper;

    @Resource
    private SvYdNumberMapper numberMapper;

    @Autowired
    private CityCoefficientMapper cityCoefficientMapper;

    // 统计部门结果得分map集合
    private HashMap<Date, ResultIndexMark> resultMap = new HashMap<>();
    //将每日部门结果装入map,计算每日最终结果
    private HashMap<Date, ControlPowerDay> resultDayMap = new HashMap<>();
    //计算最大主体部门
    private HashMap<Double, String> getMaxMainMap = new HashMap<>();
    //计算最大协同部门
    private HashMap<Double, String> getMaxCoorMap = new HashMap<>();
    //打印输出清单指数报告
    static ConcurrentHashMap<String, PrintResult> printResultMap = new ConcurrentHashMap<>();

    //获得管控力方法主体
    public void getControlMark(String startDate) throws ParseException {

        //日期格式转化
        String incrementDate = GetDateUtils.getIncrementDate(startDate);
        String stockDate = GetDateUtils.getStockDate(startDate);

        //各部门最终结果集合
        List<DepartmentControlMark> resultList = new LinkedList();

        //查所有城市比例系数
        List<CityCoefficient> cityCoefficients = cityCoefficientMapper.selectList(null);

        //城市比例系数map, 键部门名,值:改部门的城市比例系数
        HashMap<String, Double> cityCoefficientMap = new HashMap<>();

        for (CityCoefficient cityCoefficient : cityCoefficients) {
            cityCoefficientMap.put(cityCoefficient.getCityName(), cityCoefficient.getCoefficient());
        }

        //查出存量数据,用于计算问题整改协同指标中,问题主体与协同的最大值
        List<Department> departments = departmentMapper.selectList(null);
        QueryWrapper<DataInfo> allDataInfoQuery = new QueryWrapper<>();
        allDataInfoQuery.lt("happen_date", incrementDate);
        allDataInfoQuery.gt("happen_date", stockDate);
        List<DataInfo> allDataInfos = dataInfoMapper.selectList(allDataInfoQuery);

        //计算各部门协同次数
        HashMap<String, DepartmentCoordination> coordinationPublicData = getCoordinationPublicData(allDataInfos);

        //计算牵头各部门次数
        HashMap<String, DepartmentMainResponsibility> mainResponsibilityData = getMainResponsibilityCount(allDataInfos);

        //计算省协作次数
        List<Integer> provinceCoorList = new ArrayList<>();

        //计算省牵头次数
        List<Integer> provinceMainList = new ArrayList<>();

        //计算市协作次数
        List<Double> cityCoorList = new ArrayList<>();

        //计算市协作次数
        List<Double> cityMainList = new ArrayList<>();

        //统计排序求最值
        computeCountList(provinceCoorList, provinceMainList, cityCoorList, cityMainList, coordinationPublicData, mainResponsibilityData, cityCoefficients, getMaxMainMap, getMaxCoorMap);


        //计算日期格式转化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        Date parseDate = sdf.parse(startDate);

        //打印输出结果,根据部门名对map进行初始化,防止出现空值调用
        for (Department department : departments) {
            printResultMap.put(department.getDepName(), new PrintResult());
        }

        // 遍历部门,根据部门查出改部门的所有数据
        for (Department department : departments) {
            //存量
            department = AreaJudgeUtils.getDepartMent(department.getDepName());
            QueryWrapper<DataInfo> dataInfoQuery = new QueryWrapper<>();
            dataInfoQuery.like("duty_unit", department.getDepName());
            dataInfoQuery.lt("happen_date", incrementDate);
            dataInfoQuery.gt("happen_date", stockDate);
            List<DataInfo> stockDataInfos = dataInfoMapper.selectList(dataInfoQuery);
            //增量
            QueryWrapper<DataInfo> dataInfoQuery2 = new QueryWrapper<>();
            dataInfoQuery2.like("duty_unit", department.getDepName());
            dataInfoQuery2.lt("happen_date", startDate);
            dataInfoQuery2.gt("happen_date", incrementDate);

            List<DataInfo> increaseDataInfos = dataInfoMapper.selectList(dataInfoQuery2);

            //无数据,跳过计算管控力
            if (stockDataInfos.isEmpty() && increaseDataInfos.isEmpty()) {
                continue;
            }

            //问题主动发现指标
            Double initiativeDiscoveryMark = getInitiativeDiscoveryMark(stockDataInfos, department, printResultMap);

            //整改销号指标
            Double reformMark = getReformMarkNew(stockDataInfos, department, cityCoefficients, printResultMap);

            //问题整改协同率
            Double questionReformMark = getQuestionReformMark(department, coordinationPublicData,
                    mainResponsibilityData, provinceCoorList, provinceMainList,
                    cityCoorList, cityMainList, cityCoefficientMap, printResultMap, getMaxMainMap, getMaxCoorMap);

            //被动发现指标
            Double passiveDiscoveryMark = getPassiveDiscoveryMark(increaseDataInfos, department, printResultMap);

            //再发复发
            Double recrudesceMark = getRecrudesce(increaseDataInfos, department, printResultMap);

            //重大问题脱漏管指标
            SeriousProblemIgnore seriousProblemIgnoreMark1 = getSeriousProblemIgnoreMark(increaseDataInfos, department, cityCoefficients, printResultMap);
            Double seriousProblemIgnoreMark = seriousProblemIgnoreMark1.getSeriousProblemIgnoreMark();

            //即知即改
            Double immediateChangeScore = getImmediateChangeScore(questionReformMark);

            //整改到位
            Double reformGoodScore = getReformGoodScore(reformMark);

            //主动发现
            Double activeDiscoveryScore = getActiveDiscoveryScore(initiativeDiscoveryMark, passiveDiscoveryMark);

            //举一反三
            Double drawInferencesScore = getDrawInferencesScore(recrudesceMark, seriousProblemIgnoreMark);

            //存量问题整改指数
            Double stockScore = initiativeDiscoveryMark + reformMark + questionReformMark;

            //增量问题新发指数
            Double repeatScore = passiveDiscoveryMark + recrudesceMark + seriousProblemIgnoreMark;

            //管控力
            Double controlPowerScore = stockScore + repeatScore;

            //省市级别
            String level = department.getLevel();

            //四项之和
            Double tempSum = immediateChangeScore + reformGoodScore + activeDiscoveryScore + drawInferencesScore;


            //各部门结果
            DepartmentControlMark controlMark = new DepartmentControlMark();
            controlMark.setReformMark(reformMark);
            controlMark.setInitiativeDiscoveryMark(initiativeDiscoveryMark);
            controlMark.setQuestionReformMark(questionReformMark);
            controlMark.setDepName(department.getDepName());
            controlMark.setSeriousProblemIgnoreMark(seriousProblemIgnoreMark);
            controlMark.setPassiveDiscoveryMark(passiveDiscoveryMark);
            controlMark.setRecrudesceMark(recrudesceMark);
            controlMark.setStockScore(stockScore);
            controlMark.setRepeatScore(repeatScore);
            controlMark.setControlPowerScore(controlPowerScore);
            controlMark.setLevel(level);
            controlMark.setComputeDate(parseDate);
            controlMark.setImmediateChangeScore(immediateChangeScore);
            controlMark.setReformGoodScore(reformGoodScore);
            controlMark.setActiveDiscoveryScore(activeDiscoveryScore);
            controlMark.setDrawInferencesScore(drawInferencesScore);
            controlMark.setTempSum(tempSum);


            //统计输出数据报告
            PrintResult printResult = printResultMap.get(department.getDepName());
            if (printResult != null) {
                double listScore = Double.parseDouble(new DecimalFormat("#.00").format(controlPowerScore));
                int stockSeriousNumber = (int) stockDataInfos.stream().filter(s -> s.getQuestionType().equals("重大")).count();
                int stockNormalNumber = stockDataInfos.size() - stockSeriousNumber;
                int increaseSeriousNumber = (int) increaseDataInfos.stream().filter(s -> s.getQuestionType().equals("重大")).count();
                int increaseNormalNumber = increaseDataInfos.size() - increaseSeriousNumber;
                int totalNumber = stockDataInfos.size() + increaseDataInfos.size();
                int totalSeriousNumber = stockSeriousNumber + increaseSeriousNumber;
                int totalNormalNumber = stockNormalNumber + increaseNormalNumber;
                int stockNumber = stockDataInfos.size();
                int increaseNumber = increaseDataInfos.size();
                Double cityCoefficient = cityCoefficientMap.get(department.getDepName());
                printResult.setCityName(department.getDepName());
                printResult.setComputingTime(parseDate);
                printResult.setTotalNumber(totalNumber);
                printResult.setTotalSeriousNumber(totalSeriousNumber);
                printResult.setTotalNormalNumber(totalNormalNumber);
                printResult.setStockNumber(stockNumber);
                printResult.setStockSeriousNumber(stockSeriousNumber);
                printResult.setStockNormalNumber(stockNormalNumber);
                printResult.setIncreaseNumber(increaseNumber);
                printResult.setIncreaseSeriousNumber(increaseSeriousNumber);
                printResult.setIncreaseNormalNumber(increaseNormalNumber);
                printResult.setCityCoefficient(cityCoefficient);
                printResult.setTotalScore(listScore);
                printResultMap.put(department.getDepName(), printResult);
            }


            //插入各部门分数
            if (!(controlMark.getInitiativeDiscoveryMark() == 0 && controlMark.getReformMark() == 0 &&
                    controlMark.getPassiveDiscoveryMark() == 0 && controlMark.getRecrudesceMark() == 0 && controlMark.getSeriousProblemIgnoreMark() == 0)) {
                controlPowerMapper.insert(controlMark);
                resultList.add(controlMark);

            }
            // TODO 区分部门和地区
//            if (department.getLevel().equals("区县级")) {
//                SvYdNumberPlaceDO svYdNumberPlaceDO = new SvYdNumberPlaceDO();
//                svYdNumberPlaceDO.setArea(department.getDepName());
//                svYdNumberPlaceDO.setDate(parseDate);
//                svYdNumberPlaceDO.setListNu(controlPowerScore);
//                svYdNumberPlaceDO.setDataValid(1);
//                numberPlaceMapper.insert(svYdNumberPlaceDO);
//            } else
            if (department.getDepName().contains("市")) {
                SvYdNumberAreaDO svYdNumberAreaDO = new SvYdNumberAreaDO();
                svYdNumberAreaDO.setDate(parseDate);
                svYdNumberAreaDO.setArea(department.getDepName());
                svYdNumberAreaDO.setAreaListNu(controlPowerScore);
                svYdNumberAreaDO.setAreaProblemNu(stockScore);
                svYdNumberAreaDO.setAreaRepeatNu(repeatScore);
                svYdNumberAreaDO.setDataValid(1);
                numberAreaMapper.insert(svYdNumberAreaDO);
            } else {
                // 部门
                SvYdNumberPartDO svYdNumberPartDO = new SvYdNumberPartDO();
                svYdNumberPartDO.setUnitName(department.getDepName());
                svYdNumberPartDO.setUnitListNu(controlPowerScore);
                svYdNumberPartDO.setUnitProblemNu(stockScore);
                svYdNumberPartDO.setDate(parseDate);
                svYdNumberPartDO.setUnitRepeatNu(repeatScore);
                svYdNumberPartDO.setDataValid(1);
                numberPartMapper.insert(svYdNumberPartDO);
            }

        }
        controlPowerDayService.getControlPowerDay(resultList, parseDate, resultDayMap);


    }


    //举一反三得分    30分
    public Double getDrawInferencesScore(Double recrudesceMark, Double seriousProblemIgnoreMark) {
        return ((30 + recrudesceMark) + (30 + seriousProblemIgnoreMark)) / 2;
    }

    //得到主动发现得分   40分
    public Double getActiveDiscoveryScore(Double initiativeDiscoveryMark, Double passiveDiscoveryMark) {
        return (initiativeDiscoveryMark + (40 + passiveDiscoveryMark)) / 2;
    }

    //得到整改到位得分   20分
    public Double getReformGoodScore(Double reformMark) {
        return reformMark / 2;
    }

    //得到即知即改得分   10分
    public Double getImmediateChangeScore(Double questionReformMark) {
        return questionReformMark / 2;
    }


    //集合排序求最值
    public void computeCountList(List<Integer> provinceCoorList, List<Integer> provinceMainList, List<Double> cityCoorList, List<Double> cityMainList,
                                 HashMap<String, DepartmentCoordination> coordinationPublicData, HashMap<String,
            DepartmentMainResponsibility> mainResponsibilityData, List<CityCoefficient> cityCoefficients, HashMap<Double, String> getMaxMainMap, HashMap<Double, String> getMaxCoorMap) {

        for (Map.Entry entry : coordinationPublicData.entrySet()) {
            Department department = AreaJudgeUtils.getDepartMent(entry.getKey().toString());
            DepartmentCoordination departmentCoordination = (DepartmentCoordination) entry.getValue();

            if (department.getLevel() != null && department.getLevel().equals("省级")) {
                provinceCoorList.add(departmentCoordination.getCoordinationCount());
            } else if (department.getLevel() != null && department.getLevel().equals("市级")) {
                for (CityCoefficient cityCoefficient : cityCoefficients) {
                    if (cityCoefficient.getCityName().equals(department.getDepName())) {
                        cityCoorList.add(departmentCoordination.getCoordinationCount() / cityCoefficient.getCoefficient());
                        getMaxCoorMap.put(departmentCoordination.getCoordinationCount() / cityCoefficient.getCoefficient(), department.getDepName());
                    }
                }

            }
        }
        provinceCoorList.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        cityCoorList.sort(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                return (int) (o2 - o1);
            }
        });

        for (Map.Entry entry : mainResponsibilityData.entrySet()) {
            //todo
            //  System.out.println("主体单位  Key: "+entry.getKey()+" Value: "+entry.getValue());

            DepartmentMainResponsibility departmentMainResponsibility = (DepartmentMainResponsibility) entry.getValue();
            Department department = AreaJudgeUtils.getDepartMent(entry.getKey().toString());
            if (department.getLevel() != null && department.getLevel().equals("省级")) {
                provinceMainList.add(departmentMainResponsibility.getMainResponsibilityCount());
            } else if (department.getLevel() != null && department.getLevel().equals("市级")) {
                for (CityCoefficient cityCoefficient : cityCoefficients) {
                    if (cityCoefficient.getCityName().equals(department.getDepName())) {
                        cityMainList.add(departmentMainResponsibility.getMainResponsibilityCount() / cityCoefficient.getCoefficient());
                        getMaxMainMap.put(departmentMainResponsibility.getMainResponsibilityCount() / cityCoefficient.getCoefficient(), department.getDepName());
                    }
                }

            }
        }
        provinceMainList.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        cityMainList.sort(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                return (int) (o2 - o1);
            }
        });

    }

    //得到提出单位的权重
    public Integer getProposeWeight(DataInfo dataInfo) {
        ArrayList<Integer> weightList = new ArrayList<>();
        String[] split = dataInfo.getProposeUnit().replaceAll(",", "、").replaceAll("，", "、").split("、");
        if (split.length > 1) {
            for (int i = 0; i < split.length; i++) {
                if (split[i].length() < 1) {
                    continue;
                }
                Department departMent = AreaJudgeUtils.getDepartMent(split[i]);
                weightList.add(departMent.getWeight());
            }
            weightList.sort(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o2 - o1;
                }
            });
            return weightList.get(0);
        } else if (split.length == 1) {
            Department departMent = AreaJudgeUtils.getDepartMent(split[0]);
            return departMent.getWeight();
        } else {
            return 0;
        }
    }

    //得到责任主体单位的权重
    public Integer getMainWeight(DataInfo dataInfo) {
        ArrayList<Integer> weightList = new ArrayList<>();
        String[] split = dataInfo.getResponsibilityMainPart().replaceAll(",", "、").replaceAll("，", "、").split("、");
        if (split.length > 1) {
            for (int i = 0; i < split.length; i++) {
                if (split[i].length() < 1) {
                    continue;
                }
                Department departMent = AreaJudgeUtils.getDepartMent(split[i]);
                weightList.add(departMent.getWeight());
            }
            weightList.sort(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o2 - o1;
                }
            });
            return weightList.get(0);
        } else if (split.length == 1) {
            Department departMent = AreaJudgeUtils.getDepartMent(split[0]);
            return departMent.getWeight();
        } else {
            return 0;
        }
    }

    //问题主体数
    public HashMap<String, DepartmentMainResponsibility> getMainResponsibilityCount(List<DataInfo> allDataInfos) {
        HashMap<String, DepartmentMainResponsibility> departmentMainResponsibilityHashMap = new HashMap<>();

        for (DataInfo dataInfo : allDataInfos) {
            if (dataInfo.getResponsibilityMainPart() != null) {
                String responsibilityMainBody = dataInfo.getResponsibilityMainPart().replaceAll(",", "、").replaceAll("，", "、");
                String[] responsibilityArray = responsibilityMainBody.split("、");

                //遍历主体单位
                for (int i = 0; i < responsibilityArray.length; i++) {
                    if (responsibilityArray[i].length() < 1) {
                        continue;
                    }
                    Department departMent = AreaJudgeUtils.getDepartMent(responsibilityArray[i]);
                    DepartmentMainResponsibility departmentMainResponsibility = departmentMainResponsibilityHashMap.get(departMent.getDepName());

                    if (departmentMainResponsibility == null) {
                        DepartmentMainResponsibility dm = new DepartmentMainResponsibility();
                        dm.setMainResponsibilityCount(1);
                        departmentMainResponsibilityHashMap.put(departMent.getDepName(), dm);
                    } else {
                        departmentMainResponsibility.setMainResponsibilityCount(departmentMainResponsibility.getMainResponsibilityCount() + 1);
                        departmentMainResponsibilityHashMap.put(departMent.getDepName(), departmentMainResponsibility);
                    }
                }
            }

        }
        departmentMainResponsibilityHashMap.remove(null);
        return departmentMainResponsibilityHashMap;

    }

    //协同单位
    public HashMap<String, DepartmentCoordination> getCoordinationPublicData(List<DataInfo> allDataInfos) {
        HashMap<String, DepartmentCoordination> departmentCoordinationHashMap = new HashMap<>();
        for (DataInfo dataInfo : allDataInfos) {
            if (dataInfo.getCoordinationMainBody() != null) {
                String coordinationMainBody = dataInfo.getCoordinationMainBody().replaceAll(",", "、").replaceAll("，", "、");
                String[] coordinationArray = coordinationMainBody.split("、");
                //遍历协作单位
                for (int i = 0; i < coordinationArray.length; i++) {
                    if (coordinationArray[i].length() < 2) {
                        continue;
                    }
                    Department departMent = AreaJudgeUtils.getDepartMent(coordinationArray[i]);
                    DepartmentCoordination departmentCoordination = departmentCoordinationHashMap.get(departMent.getDepName());
                    if (departmentCoordination == null) {
                        DepartmentCoordination dc = new DepartmentCoordination();
                        dc.setCoordinationCount(1);
                        departmentCoordinationHashMap.put(departMent.getDepName(), dc);
                    } else {
                        departmentCoordination.setCoordinationCount(departmentCoordination.getCoordinationCount() + 1);
                        departmentCoordinationHashMap.put(departMent.getDepName(), departmentCoordination);
                    }
                }
            }
        }
        departmentCoordinationHashMap.remove(null);
        return departmentCoordinationHashMap;
    }


    //问题主动发现指标
    public Double getInitiativeDiscoveryMark(List<DataInfo> stockDataInfos, Department department, ConcurrentHashMap<String, PrintResult> printResultMap) {

        List<DataInfo> seriousData = new ArrayList<>();
        List<DataInfo> normalData = new ArrayList<>();
        //计算存量数据
        double stockMark = 0;
        //问题主动发现非重大指标分子
        double stockNumeratorNormal = 0;
        //问题主动发现重大指标分子
        double stockNumeratorSerious = 0;

        int activeNumber = 0;
        int activeSeriousNumber = 0;
        int activeNormalNumber = 0;
        double activeScore = 0d;

        //遍历数据区分重大非重大
        for (DataInfo stockDataInfo : stockDataInfos) {
            if (stockDataInfo.getQuestionType().equals("重大")) {
                seriousData.add(stockDataInfo);
            } else {
                normalData.add(stockDataInfo);
            }
        }
        //主动发现分母
        double stockDenominator = normalData.size() + 20 * seriousData.size();
        for (DataInfo seriousDatum : seriousData) {
            //Department judgeDepartMent = AreaJudgeUtils.getDepartMent(seriousDatum.getProposeUnit());
            Integer proposeWeight = getProposeWeight(seriousDatum);
            //提出单位的权重不大于主体单位为主动
            if (!(proposeWeight > department.getWeight())) {
                stockNumeratorSerious += 1;
            }
            activeSeriousNumber = (int) stockNumeratorSerious;
        }
        for (DataInfo normalDatum : normalData) {
            // Department judgeDepartMent = AreaJudgeUtils.getDepartMent(normalDatum.getProposeUnit());
            Integer proposeWeight = getProposeWeight(normalDatum);
            if (!(proposeWeight > department.getWeight())) {
                stockNumeratorNormal += 1;
            }
            activeNormalNumber = (int) stockNumeratorNormal;
        }

        if (stockDenominator > 0) {
            stockMark = 40 * 0.6 + 40 * 0.4 * ((stockNumeratorNormal + 20 * stockNumeratorSerious) / stockDenominator);
            activeScore = stockMark;
        }

        //统计输出结果

        PrintResult printResult = printResultMap.get(department.getDepName());

        if (printResult != null) {
            double getActiveScore = Double.parseDouble(new DecimalFormat("#.00").format(activeScore));
            printResult.setActiveSeriousNumber(activeSeriousNumber);
            printResult.setActiveNormalNumber(activeNormalNumber);
            printResult.setActiveNumber(activeSeriousNumber + activeNormalNumber);
            printResult.setActiveScore(getActiveScore);
            printResultMap.put(department.getDepName(), printResult);
        }
        return stockMark;
    }

    //问题整改指标调整
    public Double getReformMarkNew(List<DataInfo> stockDataInfos, Department department, List<CityCoefficient> cityCoefficients, ConcurrentHashMap<String, PrintResult> printResultMap) {
        double reformMark = 0d;
        double getQuestionCancelScore = 0d;
        List<DataInfo> cancelList = new ArrayList<>();
        List<DataInfo> notCancelList = new ArrayList<>();
        List<DataInfo> seriousList = new ArrayList<>();
        //重大/非重大分类计算
        //如果是今年的未销号,暂时算这条数据已销号
        for (DataInfo dataInfo : stockDataInfos) {
            if (dataInfo.getIsCancel().equals(CancelTypeEnum.NO.getValue())) {
                // 方案二：大于当年的1月1号  TODO
                Date yearFirst = GetDateUtils.getYearFirst(2021);
                if (dataInfo.getTime().getTime() >= yearFirst.getTime()) {
                    dataInfo.setIsCancel(CancelTypeEnum.YES.getValue());
                }
            }

            if (dataInfo.getIsCancel().equals(CancelTypeEnum.YES.getValue())) {

                cancelList.add(dataInfo);
            } else {
                notCancelList.add(dataInfo);
            }
        }
        //统计重大为销号的个数
        for (DataInfo dataInfo : notCancelList) {
            if (dataInfo.getQuestionType().equals("重大")) {
                seriousList.add(dataInfo);
            }
        }
        double proportion = (double) cancelList.size() / (double) stockDataInfos.size();
        if (proportion >= 0.8) {
            reformMark = 40;
        } else if (proportion >= 0.7 && proportion < 0.8) {
            reformMark = 30;
        } else if (proportion >= 0.6 && proportion < 0.7) {
            reformMark = 20;
        } else if (proportion >= 0.5 && proportion < 0.6) {
            reformMark = 10;
        } else if (proportion <= 0.5) {
            reformMark = 0;
        }
        getQuestionCancelScore = reformMark;

        //统计输出结果
        PrintResult printResult = printResultMap.get(department.getDepName());
        if (printResult != null) {
            double tempQuestionCancelScore = Double.parseDouble(new DecimalFormat("#.00").format(getQuestionCancelScore));
            printResult.setCancelAfterScore(tempQuestionCancelScore);
            printResultMap.put(department.getDepName(), printResult);
        }

        if (AreaJudgeUtils.getDepartMent(department.getDepName()).getLevel().equals("市级")) {
            for (CityCoefficient cityCoefficient : cityCoefficients) {
                if (cityCoefficient.getCityName().equals(department.getDepName())) {
                    reformMark = reformMark - seriousList.size() / cityCoefficient.getCoefficient() * 5;
                }
            }
        } else {
            reformMark = reformMark - seriousList.size() * 5;
        }

        if (reformMark < 0) {
            reformMark = 0;
        }
        reformMark = 24 + reformMark * 0.4;

        //统计输出结果
        double questionCancelScore = Double.parseDouble(new DecimalFormat("#.00").format(reformMark));
        if (printResult != null) {
            printResult.setCancelProportion(proportion * 100);
            printResult.setNotCancelNumber(seriousList.size());
            printResult.setQuestionCancelScore(questionCancelScore);
            printResultMap.put(department.getDepName(), printResult);
        }
        return reformMark;
    }

    //问题整改协同指标
    public Double getQuestionReformMark(Department department, HashMap<String,
            DepartmentCoordination> coordinationPublicData, HashMap<String,
            DepartmentMainResponsibility> mainResponsibilityData, List<Integer> provincecoorList,
                                        List<Integer> provincemainList, List<Double> citycoorList, List<Double> citymainList,
                                        HashMap<String, Double> cityCoefficientMap,
                                        ConcurrentHashMap<String, PrintResult> printResultMap, HashMap<Double, String> getMaxMainMap, HashMap<Double, String> getMaxCoorMap) {
        String depName = department.getDepName();
        //得到主体部门的个数
        double mainResponsibilityCount = 0d;
        if (mainResponsibilityData.get(depName) != null) {
            mainResponsibilityCount = mainResponsibilityData.get(depName).getMainResponsibilityCount();
        }
        //得到协同部门的个数
        double coordinationCount = 0d;
        if (coordinationPublicData.get(depName) != null) {
            coordinationCount = coordinationPublicData.get(depName).getCoordinationCount();
        }
        double mainMark = 0d;
        double coorMark = 0d;
        //省级的不需要除以城市比例系数
        if (department.getLevel() != null && department.getLevel().equals("省级")) {
            if (provincemainList != null && provincemainList.size() > 0) {
                mainMark = mainResponsibilityCount / provincemainList.get(0) * 12d;
            }
            if (provincecoorList != null && provincecoorList.size() > 0) {
                coorMark = coordinationCount / provincecoorList.get(0) * 8d;
                if (coordinationCount == 0) {
                    coorMark = 8d;
                }
            }
            //如果是市级的需要除以城市比例系数
        } else if (department.getLevel() != null && department.getLevel().equals("市级")) {
            Double cityCoefficientMark = cityCoefficientMap.get(department.getDepName());

            if (citymainList != null && citymainList.size() > 0) {
                mainMark = (mainResponsibilityCount / cityCoefficientMark) / citymainList.get(0) * 12d;
            }
            if (citycoorList != null && citycoorList.size() > 0) {
                coorMark = ((coordinationCount / cityCoefficientMark) / citycoorList.get(0)) * 8d;
                if (coordinationCount == 0) {
                    coorMark = 8d;
                }
            }
        }
        Double questionReformMark = 20 * 0.6 + 0.4 * (mainMark + coorMark);


        //统计输出结果

        //省部门最大名称
        DepartmentMainResponsibility departmentMainResponsibility = new DepartmentMainResponsibility();
        departmentMainResponsibility.setMainResponsibilityCount(provincemainList.get(0));
        String mainDepName = GetMapKeyUtils.getKey1(mainResponsibilityData, departmentMainResponsibility);
        DepartmentCoordination departmentCoordination = new DepartmentCoordination();
        departmentCoordination.setCoordinationCount(provincecoorList.get(0));
        String coorDepName = GetMapKeyUtils.getKey2(coordinationPublicData, departmentCoordination);


        double maxMainReformNumber = 0d;
        double getMaxMainReformNumber = 0d;
        if (citymainList != null && citymainList.size() != 0) {
            maxMainReformNumber = citymainList.get(0);
            getMaxMainReformNumber = Double.parseDouble(new DecimalFormat("#.00").format(maxMainReformNumber));
        }

        double maxCoorReformNumber = 0d;
        double getMaxCoorReformNumber = 0d;
        if (citycoorList != null && citycoorList.size() != 0) {
            maxCoorReformNumber = citycoorList.get(0);
            getMaxCoorReformNumber = Double.parseDouble(new DecimalFormat("#.00").format(maxCoorReformNumber));
        }
        Double cityCoefficientMark = cityCoefficientMap.get(department.getDepName());

        PrintResult printResult = printResultMap.get(department.getDepName());
        double getQuestionReformScore = Double.parseDouble(new DecimalFormat("#.00").format(questionReformMark));
        if (printResult != null && citymainList != null && citymainList.get(0) != null && getMaxMainMap.get(citymainList.get(0)) != null
                && citycoorList != null && getMaxCoorMap.get(citycoorList.get(0)) != null && citycoorList.get(0) != null) {
            String mainName = getMaxMainMap.get(citymainList.get(0));
            Double maxMainCityCoefficient = cityCoefficientMap.get(mainName);
            double maxMainQuestionNumber = citymainList.get(0) * maxMainCityCoefficient;
            int mainQuestionNumber = new Double(maxMainQuestionNumber).intValue();

            String coorName = getMaxCoorMap.get(citycoorList.get(0));
            Double maxCoorCityCoefficient = cityCoefficientMap.get(coorName);
            double maxCoorQuestionNumber = citycoorList.get(0) * maxCoorCityCoefficient;
            int coorQuestionNumber = new Double(maxCoorQuestionNumber).intValue();

            //市级部门
            printResult.setCityMainReformNumber(new Double(mainResponsibilityCount).intValue());
            printResult.setCityCoorReformNumber(new Double(coordinationCount).intValue());
            printResult.setMaxMainDepName(mainName);
            printResult.setMaxCoorDepName(coorName);
            printResult.setMaxMainQuestionNumber(mainQuestionNumber);
            printResult.setMaxCoorQuestionNumber(coorQuestionNumber);
            printResult.setMaxMainCityCoefficient(maxMainCityCoefficient);
            printResult.setMaxCoorCityCoefficient(maxCoorCityCoefficient);
            printResult.setMaxMainReformNumber(getMaxMainReformNumber);
            printResult.setMaxCoorReformNumber(getMaxCoorReformNumber);
            printResult.setCityCoefficient(cityCoefficientMark);
            printResult.setReformCoordinateScore(getQuestionReformScore);
            //省级部门
            printResult.setProvinceMainDepName(mainDepName);
            printResult.setProvinceCoorDepName(coorDepName);
            printResult.setProvinceMainNumber(new Double(mainResponsibilityCount).intValue());
            printResult.setProvinceCoorNumber(new Double(coordinationCount).intValue());
            printResult.setMaxProvinceMainNumber(provincemainList.get(0));
            printResult.setMaxProvinceCoorNumber(provincecoorList.get(0));
            printResultMap.put(department.getDepName(), printResult);
        }
        return questionReformMark;
    }


    //被动发现指数
    public Double getPassiveDiscoveryMark(List<DataInfo> increaseDataInfos, Department department, ConcurrentHashMap<String, PrintResult> printResultMap) {
        List<DataInfo> seriousData = new ArrayList<>();
        List<DataInfo> normalData = new ArrayList<>();
        //计算存量数据
        double passiveDiscoveryMark = 0;
        //问题主动发现非重大指标分子
        double increaseNumeratorNormal = 0;
        //问题主动发现重大指标分子
        double increaseNumeratorSerious = 0;
        for (DataInfo increaseDataInfo : increaseDataInfos) {
            if (increaseDataInfo.getQuestionType().equals("重大")) {
                seriousData.add(increaseDataInfo);
            } else {
                normalData.add(increaseDataInfo);
            }
        }
        double stockDenominator = normalData.size() + 20 * seriousData.size();
        for (DataInfo seriousDatum : seriousData) {
            //  Department judgeDepartMent = AreaJudgeUtils.getDepartMent(seriousDatum.getProposeUnit());
            Integer proposeWeight = getProposeWeight(seriousDatum);
            if (proposeWeight > department.getWeight()) {
                increaseNumeratorSerious += 1;
            }
        }
        for (DataInfo normalDatum : normalData) {
            // Department judgeDepartMent = AreaJudgeUtils.getDepartMent(normalDatum.getProposeUnit());
            Integer proposeWeight = getProposeWeight(normalDatum);
            if (proposeWeight > department.getWeight()) {
                increaseNumeratorNormal += 1;
            }
        }
        if (stockDenominator > 0) {
            passiveDiscoveryMark = -(40 * 0.4 * ((increaseNumeratorNormal + 20 * increaseNumeratorSerious) / stockDenominator));
        }


        //输出结果
        PrintResult printResult = printResultMap.get(department.getDepName());
        double getPassiveDiscoveryMark = Double.parseDouble(new DecimalFormat("#.00").format(passiveDiscoveryMark));
        if (printResult != null) {
            printResult.setPassiveNumber((int) (increaseNumeratorSerious + increaseNumeratorNormal));
            printResult.setPassiveSeriousNumber((int) increaseNumeratorSerious);
            printResult.setPassiveNormalNumber((int) increaseNumeratorNormal);
            printResult.setPassiveScore(getPassiveDiscoveryMark);
            printResultMap.put(department.getDepName(), printResult);
        }
        return passiveDiscoveryMark;
    }

    //问题再发复发指标
    public Double getRecrudesce(List<DataInfo> increaseDataInfos, Department department, ConcurrentHashMap<String, PrintResult> printResultMap) {
        List<DataInfo> seriousData = new ArrayList<>();
        List<DataInfo> normalData = new ArrayList<>();
        //计算存量数据
        double recrudesceMark = 0;
        //问题主动发现非重大指标分子
        double increaseNumeratorNormal = 0;
        //问题主动发现重大指标分子
        double increaseNumeratorSerious = 0;
        for (DataInfo increaseDataInfo : increaseDataInfos) {
            if (increaseDataInfo.getQuestionType().equals("重大")) {
                seriousData.add(increaseDataInfo);
            } else {
                normalData.add(increaseDataInfo);
            }
        }

        //再发复发分母
        double stockDenominator = normalData.size() + 30 * seriousData.size();
        for (DataInfo seriousDatum : seriousData) {
            if (seriousDatum.getQuestionQuality() == null) {
                continue;
            }
            if (seriousDatum.getQuestionQuality().contains("复发再发")) {
                increaseNumeratorSerious += 1;
            }
        }
        for (DataInfo normalDatum : normalData) {
            if (normalDatum.getQuestionQuality() == null) {
                continue;
            }
            if (normalDatum.getQuestionQuality().contains("复发再发")) {
                increaseNumeratorNormal += 1;
            }
        }
        if (stockDenominator > 0) {
            recrudesceMark = -(30 * 0.4 * ((increaseNumeratorNormal + 30 * increaseNumeratorSerious) / stockDenominator));
        }


        //输出结果
        PrintResult printResult = printResultMap.get(department.getDepName());
        double getRecrudesceMark = Double.parseDouble(new DecimalFormat("#.00").format(recrudesceMark));
        if (printResult != null) {
            printResult.setRecurSeriousNumber((int) increaseNumeratorSerious);
            printResult.setRecurNormalNumber((int) increaseNumeratorNormal);
            printResult.setRecurScore(getRecrudesceMark);
            printResultMap.put(department.getDepName(), printResult);
        }
        return recrudesceMark;
    }

    //重大问题脱漏管
    public SeriousProblemIgnore getSeriousProblemIgnoreMark(List<DataInfo> increaseDataInfos, Department department, List<CityCoefficient> cityCoefficients, ConcurrentHashMap<String, PrintResult> printResultMap) {
        List<String> deductions = new LinkedList<>();
        int countryDiscoveryNumber = 0;
        int centerDiscoveryNumber = 0;
        int provinceDiscoveryNumber = 0;
        int cityDiscoveryNumber = 0;

        SeriousProblemIgnore seriousProblemIgnore = new SeriousProblemIgnore();
        double seriousProblemIgnoreMark = 0d;
        for (DataInfo increaseDataInfo : increaseDataInfos) {
            String questionResource = increaseDataInfo.getQuestionResource();
            // Department judgeDepartMent = AreaJudgeUtils.getDepartMent(increaseDataInfo.getProposeUnit());
            if (questionResource == null) {
                continue;
            }
            if (questionResource.contains("中央和国家") && questionResource.contains("部委督查")) {
                deductions.add(questionResource + "-5分");
                seriousProblemIgnoreMark -= 5;
                countryDiscoveryNumber += 1;
            } else if (questionResource.contains("中央") || questionResource.contains("国务院")) {
                deductions.add(questionResource + "-10分");
                seriousProblemIgnoreMark -= 10;
                centerDiscoveryNumber += 1;
            }
            if (questionResource.contains("省")) {
                if (questionResource.contains("省委办公厅") || questionResource.contains("省政府办公厅")) {
                    deductions.add(questionResource + "-2分");
                    seriousProblemIgnoreMark -= 2;
                    provinceDiscoveryNumber += 1;
                }
                if (questionResource.contains("市")) {
                    deductions.add(questionResource + "-0.5分");
                    seriousProblemIgnoreMark -= 0.5;
                    cityDiscoveryNumber += 1;
                }
            }
        }
        //如果是市级部门要除以城市比例系数
        if (department.getDepName().contains("市")) {
            for (CityCoefficient cityCoefficient : cityCoefficients) {
                if (cityCoefficient.getCityName().equals(department.getDepName())) {
                    seriousProblemIgnoreMark = seriousProblemIgnoreMark / cityCoefficient.getCoefficient();
                }
            }
        }
        if (seriousProblemIgnoreMark < -30) {
            seriousProblemIgnoreMark = -30;
        }
        seriousProblemIgnore.setDeductions(deductions);
        seriousProblemIgnore.setSeriousProblemIgnoreMark(seriousProblemIgnoreMark * 0.4);

        //输出结果

        PrintResult printResult = printResultMap.get(department.getDepName());
        double getIgnoreScore = Double.parseDouble(new DecimalFormat("#.00").format(seriousProblemIgnore.getSeriousProblemIgnoreMark()));
        if (printResult != null) {
            printResult.setCountryDiscoveryNumber(countryDiscoveryNumber);
            printResult.setCenterDiscoveryNumber(centerDiscoveryNumber);
            printResult.setProvinceDiscoveryNumber(provinceDiscoveryNumber);
            printResult.setCityDiscoveryNumber(cityDiscoveryNumber);
            printResult.setIgnoreScore(getIgnoreScore);
            printResultMap.put(department.getDepName(), printResult);
        }
        return seriousProblemIgnore;
    }


    //通过日期计算管控力指数
    public void getControlMarkByDate(String startDate, int num) throws ParseException {
        // 清空数据
        numberMapper.delete(null);
        numberAreaMapper.delete(null);
        numberPartMapper.delete(null);
        controlPowerMapper.delete(null);
        numberPlaceMapper.delete(null);

        for (int i = 0; i < num; i++) {
            String start = GetDateUtils.manyDate(startDate, i);
            System.out.println(start);
            getControlMark(start);
        }
        //计算每月得分
        controlPowerMonthService.getControlPowerMonth();
    }

    //统计输出结果
    public void getResult() {
        HashMap<String, String> resultMap = new HashMap<>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

        for (Map.Entry<String, PrintResult> entry : printResultMap.entrySet()) {
            if (entry.getValue().getCityName() == null) {
                printResultMap.remove(entry.getKey());
                continue;
            }
            String level = AreaJudgeUtils.getDepartMent(entry.getKey()).getLevel();
            if (level.equals("市级")) {
                PrintResult printResult = entry.getValue();
                String time = formatter.format(printResult.getComputingTime());
                String txt = " " + time + "\n  本单位计入计算周期问题数" + printResult.getTotalNumber() + "条（重大问题" + printResult.getTotalSeriousNumber() + "条，非重大问题" + printResult.getTotalNormalNumber() + "条），其中增量问题" + printResult.getIncreaseNumber() + "条（重大问题" + printResult.getIncreaseSeriousNumber() + "条，非重大问题" + printResult.getIncreaseNormalNumber() + "条），" +
                        "存量问题" + printResult.getStockNumber() + "条（重大问题" + printResult.getStockSeriousNumber() + "条，非重大问题" + printResult.getStockNormalNumber() + "条）。最后总得分为" + printResult.getTotalScore() + "。" +
                        "注：该城市人口比例为" + printResult.getCityCoefficient() + "\n" +
                        "（一）存量问题整改指数。\n" +
                        " 本单位主动发现" + printResult.getActiveNumber() + "条（重大" + printResult.getActiveSeriousNumber() + "条，非重大" + printResult.getActiveNormalNumber() + "条）。\n" +
                        "      1.问题主动发现指标（40分）。根据公式计算“问题主动发现指标=40×（本级发现且由本单位牵头整改的一般问题数+20×本级发现且由本单位牵头整改的重大问题数）/(本单位牵头整改的一般问题数+20×本单位牵头整改的重大问题数）”，[40*0.6+40×0.4*（" + printResult.getActiveNormalNumber() + "+20*" + printResult.getActiveSeriousNumber() + "）/(" + printResult.getStockNormalNumber() + "+20*" + printResult.getStockSeriousNumber() + ")]，该指标得分为" + printResult.getActiveScore() + "分。\n" +
                        "      2.问题整改销号指标（40分）。根据公式计算“非重大问题，销号率>=80%,给40分；70<=销号率<80%,给30分；60<=销号率<70%,给20分；50<=销号率<60%,给10分；销号率<50%,给0分；重大问题按个扣分，并算上对应城市系数”，本单位销号率为" + printResult.getCancelProportion() + "%，得分" + printResult.getCancelAfterScore() + "，重大问题未消耗" + printResult.getNotCancelNumber() + "个，计算为[" + printResult.getCancelAfterScore() + "-5×" + printResult.getNotCancelNumber() + "/" + printResult.getCityCoefficient() + "]，基础分给60%,该指标得分为" + printResult.getQuestionCancelScore() + "分。\n" +
                        "      3.问题整改协同指标（20分）。根据计算公式“12×（本单位牵头整改问题总数/城市规模系数）/（各单位牵头整改问题总数/该市城市规模系数）的最大值+8×（本单位会办整改问题总数/城市规模系数）/（各单位会办整改问题总数/该市城市规模系数）的最大值”，计算得分为12×（" + printResult.getCityMainReformNumber() + "/" + printResult.getCityCoefficient() + "）/" + printResult.getMaxMainReformNumber() + "+8×（" + printResult.getCityCoorReformNumber() + "/" + printResult.getCityCoefficient() + "）/" + printResult.getMaxCoorReformNumber() + ",基础分为60%，最后得分为" + printResult.getReformCoordinateScore() + "。" +
                        "该市主体问题数为" + printResult.getCityMainReformNumber() + ",该市协同问题数" + printResult.getCityCoorReformNumber() + ",最大数的主体部门名称" + printResult.getMaxMainDepName() + ",最大市协同部门名称" + printResult.getMaxCoorDepName() + ",最大市主体问题数" + printResult.getMaxMainQuestionNumber() + ",最大市主体部门城市比例" + printResult.getMaxMainCityCoefficient() + ",最大市协同问题数" + printResult.getMaxCoorQuestionNumber() + ",最大协同市人口比例系数" + printResult.getMaxCoorCityCoefficient() + ",市主体问题与人口比例的最大值" + printResult.getMaxMainReformNumber() + ",市协同问题与人口比例的最大值" + printResult.getMaxCoorReformNumber() + ",该市人口比例系数" + printResult.getCityCoefficient() + "\n" +

                        "（二）问题新发复发指数。\n" +
                        " 本单位被动发现" + printResult.getPassiveNumber() + "条（重大" + printResult.getPassiveSeriousNumber() + "条，非重大" + printResult.getPassiveNormalNumber() + "条）。\n" +
                        "      1. 问题被动发现指标（40分）。本指标实行扣分制，最多扣40分。根据公式“0.4*40×（上级发现且由本单位牵头整改的一般问题数+20×上级发现且由本单位牵头整改的重大问题数）/（本单位牵头整改的一般问题总数+20×本单位牵头整改的重大问题总数）”，[40×（" + printResult.getPassiveNormalNumber() + "+20*" + printResult.getPassiveSeriousNumber() + "）/(" + printResult.getIncreaseNormalNumber() + "+20*" + printResult.getIncreaseSeriousNumber() + ")]，该指标得分为" + printResult.getPassiveScore() + "分。\n" +
                        "      2.问题再发复发指标（30分）。本指标实行扣分制，最多扣30分。根据公式“30×0.4（增量问题中再发复发的一般问题数+30×增量问题再发复发的重大问题数）/（增量问题中的一般问题数+30×增量问题中的重大问题数）”，30×0.4（" + printResult.getRecurNormalNumber() + "+30×" + printResult.getRecurSeriousNumber() + "）/（" + printResult.getIncreaseNormalNumber() + "+30×" + printResult.getIncreaseSeriousNumber() + "），最终得分为" + printResult.getRecurScore() + "。\n" +
                        "      3. 重大问题脱管漏管指标（30分）。本指标实行扣分制，最多扣30分。根据公式“重大问题脱漏管指标=[国家层面督查发现问题扣分（10分/次）+中央机关和国家部委督查发现问题扣分（5分/次）+省级层面督查发现问题扣分（2分/次）+省直单位督查发现问题扣分（0.5分/次）]/城市规模系数”，本单位共有国家层面督查发现问题" + printResult.getCountryDiscoveryNumber() + "个，中央机关和国家部委督查发现问题" + printResult.getCenterDiscoveryNumber() + "个，省级层面督查发现问题" + printResult.getProvinceDiscoveryNumber() + "个，省直单位督查发现问题" + printResult.getCityDiscoveryNumber() + "个，最终得分为" + printResult.getIgnoreScore() + "。\n" +
                        "综上，本单位最终得分为" + printResult.getTotalScore() + "分.";
                resultMap.put(entry.getKey(), txt);
                SaveMapResultUtils.writeMapResult(resultMap, entry.getKey());
                resultMap.remove(entry.getKey());
            } else if (level.equals("省级")) {
                PrintResult printResult = entry.getValue();
                String time = formatter.format(printResult.getComputingTime());
                String txt = " " + time + "\n  本单位计入计算周期问题数" + printResult.getTotalNumber() + "条（重大问题" + printResult.getTotalSeriousNumber() + "条，非重大问题" + printResult.getTotalNormalNumber() + "条），其中增量问题" + printResult.getIncreaseNumber() + "条（重大问题" + printResult.getIncreaseSeriousNumber() + "条，非重大问题" + printResult.getIncreaseNormalNumber() + "条），" +
                        "存量问题" + printResult.getStockNumber() + "条（重大问题" + printResult.getStockSeriousNumber() + "条，非重大问题" + printResult.getStockNormalNumber() + "条）。最后总得分为" + printResult.getTotalScore() + "。" + "\n" +
                        "（一）存量问题整改指数。\n" +
                        " 本单位主动发现" + printResult.getActiveNumber() + "条（重大" + printResult.getActiveSeriousNumber() + "条，非重大" + printResult.getActiveNormalNumber() + "条）。\n" +
                        "      1.问题主动发现指标（40分）。根据公式计算“问题主动发现指标=40×（本级发现且由本单位牵头整改的一般问题数+20×本级发现且由本单位牵头整改的重大问题数）/(本单位牵头整改的一般问题数+20×本单位牵头整改的重大问题数）”，[40*0.6+40×0.4*（" + printResult.getActiveNormalNumber() + "+20*" + printResult.getActiveSeriousNumber() + "）/(" + printResult.getStockNormalNumber() + "+20*" + printResult.getStockSeriousNumber() + ")]，该指标得分为" + printResult.getActiveScore() + "分。\n" +
                        "      2.问题整改销号指标（40分）。根据公式计算“非重大问题，销号率>=80%,给40分；70<=销号率<80%,给30分；60<=销号率<70%,给20分；50<=销号率<60%,给10分；销号率<50%,给0分；重大问题按个扣分，并算上对应城市系数”，本单位销号率为" + printResult.getCancelProportion() + "%，得分" + printResult.getCancelAfterScore() + "，重大问题未消耗" + printResult.getNotCancelNumber() + "个，计算为[" + printResult.getCancelAfterScore() + "-5×" + printResult.getNotCancelNumber() + "/" + printResult.getCityCoefficient() + "]，基础分给60%,该指标得分为" + printResult.getQuestionCancelScore() + "分。\n" +
                        "      3.问题整改协同指标（20分）。根据计算公式“12×本单位牵头整改问题总数/各单位牵头整改问题数最大值+8×本单位会办整改问题数/各单位会办整改问题数的最大值”，计算得分为12×" + printResult.getProvinceMainNumber() + "/" + printResult.getMaxProvinceMainNumber() + "+8×" + printResult.getProvinceCoorNumber() + "/" + printResult.getMaxProvinceCoorNumber() + ",基础分为60%，最后得分为" + printResult.getReformCoordinateScore() + "。" +
                        "该单位主体问题数为" + printResult.getProvinceMainNumber() + ",该单位协同问题数" + printResult.getProvinceCoorNumber() + ",问题主体数最多部门名称" + printResult.getProvinceMainDepName() + ",协同最多部门名称" + printResult.getProvinceCoorDepName() + ",最多单位主体问题数" + printResult.getMaxProvinceMainNumber() + ",协同最大单位协同数" + printResult.getMaxProvinceCoorNumber() + "。\n" +
                        "（二）问题新发复发指数。\n" +
                        " 本单位被动发现" + printResult.getPassiveNumber() + "条（重大" + printResult.getPassiveSeriousNumber() + "条，非重大" + printResult.getPassiveNormalNumber() + "条）。\n" +
                        "      1. 问题被动发现指标（40分）。本指标实行扣分制，最多扣40分。根据公式“0.4*40×（上级发现且由本单位牵头整改的一般问题数+20×上级发现且由本单位牵头整改的重大问题数）/（本单位牵头整改的一般问题总数+20×本单位牵头整改的重大问题总数）”，[40×（" + printResult.getPassiveNormalNumber() + "+20*" + printResult.getPassiveSeriousNumber() + "）/(" + printResult.getIncreaseNormalNumber() + "+20*" + printResult.getIncreaseSeriousNumber() + ")]，该指标得分为" + printResult.getPassiveScore() + "分。\n" +
                        "      2.问题再发复发指标（30分）。本指标实行扣分制，最多扣30分。根据公式“30×0.4（增量问题中再发复发的一般问题数+30×增量问题再发复发的重大问题数）/（增量问题中的一般问题数+30×增量问题中的重大问题数）”，30×0.4（" + printResult.getRecurNormalNumber() + "+30×" + printResult.getRecurSeriousNumber() + "）/（" + printResult.getIncreaseNormalNumber() + "+30×" + printResult.getIncreaseSeriousNumber() + "），最终得分为" + printResult.getRecurScore() + "。\n" +
                        "      3. 重大问题脱管漏管指标（30分）。本指标实行扣分制，最多扣30分。根据公式“重大问题脱漏管指标=国家层面督查发现问题扣分（10分/次）+中央机关和国家部委督查发现问题扣分（5分/次）+省级层面督查发现问题扣分（2分/次）+省直单位督查发现问题扣分（0.5分/次）”，本单位共有国家层面督查发现问题" + printResult.getCountryDiscoveryNumber() + "个，中央机关和国家部委督查发现问题" + printResult.getCenterDiscoveryNumber() + "个，省级层面督查发现问题" + printResult.getProvinceDiscoveryNumber() + "个，省直单位督查发现问题" + printResult.getCityDiscoveryNumber() + "个，最终得分为" + printResult.getIgnoreScore() + "。\n" +
                        "综上，本单位最终得分为" + printResult.getTotalScore() + "分.";
                resultMap.put(entry.getKey(), txt);
                SaveMapResultUtils.writeMapResult(resultMap, entry.getKey());
                resultMap.remove(entry.getKey());
            }
        }
    }
}
